#include "state.h"
#include "conversion.h"

#include <iostream>
#include <fstream>
#include <cstdlib>


#include <unistd.h>
#include <time.h>

using namespace std;

int main(int argc, char** argv)
{
    int init, rank;
    int n = 5;
    shmem_init(&argc, &argv);

    srand(time(NULL));

    complexd h[] = {
        complexd(1/sqrt(2), 0), complexd( 1/sqrt(2), 0),
        complexd(1/sqrt(2), 0), complexd(-1/sqrt(2), 0)
    };

    Conversion H1(2,2,h);
    Conversion H2(2,2,h);
    Conversion H3(2,2,h);

    //State state(16);

 //   State state1(3), state2(3);

/*
    complexd a[] =  {
        complexd(1,0), complexd(2,0), complexd(3,0), complexd(4,0),
        complexd(5,0), complexd(6,0), complexd(7,0), complexd(8,0),
    };
    complexd b[] =  {
        complexd(1,0), complexd(0,0), complexd(0,0), complexd(0,0),
        complexd(0,0), complexd(0,0), complexd(0,0), complexd(0,0),
    };
    state1.intentionalFill(8,b);
    state2.intentionalFill(8,b);
*/
/*
    ofstream out("sample");
    out << state1;
    double time  =  shmem_time();
    state1.doConversion(H,1);
    time  =  shmem_time() - time;
    out << state1;
    if (shmem_my_pe() == 0)
        cout << "Time = " << time << endl;
        */

/*
    ofstream out("sample");
    double time  =  shmem_time();
    state.randomFill();
    out << state;
    time  =  shmem_time() - time;
    if (shmem_my_pe() == 0)
        cout << "Time = " << time << endl;
        */
    /*
    complexd b[] =  {
        complexd(1,0), complexd(0,0), complexd(0,0), complexd(0,0),
        complexd(1,0), complexd(0,0), complexd(0,0), complexd(0,0),
    };
    State state(3);
    state.intentionalFill(8,b);
    ofstream file("file");
    file << state;
    */

/*
    ifstream sample("sample");
    State state(16);
    sample >> state;
    state.n0Conversion(H);
    ofstream output("output");
    output << state;
    */
    double time;
    time = shmem_time();

    //State state25(25);
    //State state26(26);
    State state27(27);
    //state25.randomFill();
    //state26.randomFill();
    state27.randomFill();

/*
    state25.nConversion(H1);
    time = shmem_time() - time;
    if (shmem_my_pe() == 0)
        cout << "Time for 25 = " << time << endl;

    time = shmem_time();
    state26.nConversion(H2);
    state26.norma();
    time = shmem_time() - time;
    if (shmem_my_pe() == 0)
        cout << "Time for 26 = " << time << endl;
        */
    time = shmem_time();
    state27.nConversion(H3);
    time = shmem_time() - time;
    if (shmem_my_pe() == 0)
        cout << "Time for 27 = " << time << endl;



    shmem_finalize();


    return 0;
}
